package com.bdqn.t350.ch02.controller;


import com.bdqn.t350.ch02.pojo.User;
import com.bdqn.t350.ch02.service.UserService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

//@Controller
@RestController
public class UserController {

    @Resource
    UserService userService;

    @RequestMapping("/page")
    //@ResponseBody
    public Object getPageList(String uname, String pwd) {
        Sort sort = new Sort(Sort.Direction.ASC, "usrId", "usrName");
        Map<String, String> map = new HashMap<>();
        if (uname != null) {
            map.put("usrName", uname);
        }
        if (pwd != null) {
            map.put("usrPassword", pwd);
        }
        Pageable pageable = PageRequest.of(0, 2, sort);
        Page<User> page = userService.findPageUser(map, pageable);
        return page;
    }
}
